//
// Created by 86176 on 2021/11/3.
//

#ifndef CHENYUENEW_IOCPPOLLINGIOACCEPTOR_H
#define CHENYUENEW_IOCPPOLLINGIOACCEPTOR_H
#define DEFAULT_COUNT 1000

#include "IoAcceptor.h"

struct threadId{
};


class IocpPollingIoAcceptor : public IoAcceptor {
    static DWORD WINAPI WorkThreadProc(LPVOID lpParameter);
    static DWORD WINAPI IdleThreadProc(LPVOID lpParameter);

protected:
    int threadNum;          //线程计划申请数目
    HANDLE *pThreadList;    //线程队列
    HANDLE idleThread;      //idle线程
    int nProcessorsCount;   //线程总数
    SOCKET socketServer;    //监听服务socket

public:
    HANDLE hPort;
    SOCKET *g_allSock;
    int threadNumAlive;
    bool *g_flag;
public:
    bool *getGFlag() const;

    const void *getHPort() const;

    SOCKET *getGAllSock() const;

    int getThreadNumAlive() const;

public:
    explicit IocpPollingIoAcceptor(int num);
    IocpPollingIoAcceptor();
    /*IocpPollingIoAcceptor(int num);
    ~IocpPollingIoAcceptor();*/

protected:
    bool NewWorkThread();

public:
    bool bind(char *port,char *ip) override;
    bool bind();
    int initLib();//初始网络库
    void notifyIdleSessions();
    bool NewNotifyIdleThread();

};



#endif //CHENYUENEW_IOCPPOLLINGIOACCEPTOR_H
